<template>
  <!-- 中国地图 -->
  <div>
    <div class="map-ball"></div>
    <div id="mapChart" class="echarts">
      <ECharts :option="option" :resize="false" />
    </div>
  </div>
</template>

<script setup lang="ts">
import echarts, { ECOption } from "@/components/ECharts/config";
import ECharts from "@/components/ECharts/index.vue";
// import mapJson from "../assets/china.json";
// import mapJson from "../assets/yunnan.json";
import mapJson from "../assets/kunming.json";

echarts.registerMap("kunming", mapJson as Parameters<typeof echarts.registerMap>[1]);

// const planePath: string =
//   "path://M1705.06,1318.313v-89.254l-319.9-221.799l0.073-208.063c0.521-84.662-26.629-121.796-63.961-121.491c-37.332-0.305-64.482,36.829-63.961,121.491l0.073,208.063l-319.9,221.799v89.254l330.343-157.288l12.238,241.308l-134.449,92.931l0.531,42.034l175.125-42.917l175.125,42.917l0.531-42.034l-134.449-92.931l12.238-241.308L1705.06,1318.313z";

const busPath: string =
  "path://877.93664 433.95072l-101.7088-111.88224a27.51488 27.51488 0 0 0-20.34176-9.00096H230.14912a23.89504 23.89504 0 0 0-23.90016 23.90016v350.1568a23.89504 23.89504 0 0 0 23.90016 23.88992h34.62144c0-38.77888 31.4368-70.22592 70.22592-70.22592s70.22592 31.44704 70.22592 70.22592h280.89856c0-38.77888 31.4368-70.22592 70.22592-70.22592s70.22592 31.44704 70.22592 70.22592h34.62144a23.89504 23.89504 0 0 0 23.90016-23.88992V452.4544a27.52512 27.52512 0 0 0-7.15776-18.50368";
const data = [
  {
    fromName: "东川区",
    toName: "晋宁区",
    coords: [
      [103.182, 26.08349],
      [102.594987, 24.666944]
    ]
  }
];

const option: ECOption = {
  tooltip: {
    trigger: "item"
  },
  grid: {
    left: "0px",
    right: "80px",
    top: "10px",
    bottom: "10px"
  },
  geo: {
    map: "kunming",
    zoom: 1.25,
    // center: [103.257588, 25.559474],
    scaleLimit: {
      min: 1
    },
    label: {
      color: "#fff",
      show: true
    },
    emphasis: {
      label: {
        color: "#fff",
        show: true
      },
      itemStyle: {
        areaColor: {
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: [
            { offset: 0, color: "#073684" },
            { offset: 1, color: "#2B91B7" }
          ]
        }
      }
    },
    roam: false,
    itemStyle: {
      areaColor: {
        x: 0,
        y: 0,
        x2: 0,
        y2: 1,
        colorStops: [
          { offset: 0, color: "#073684" },
          { offset: 1, color: "#061E3D" }
        ]
      },
      borderColor: new echarts.graphic.LinearGradient(
        0,
        0,
        0,
        1,
        [
          { offset: 0, color: "#00F6FF" },
          { offset: 1, color: "#87ADCB" }
        ],
        false
      ),
      shadowColor: "rgba(10,76,139,1)",
      shadowOffsetY: 0,
      shadowBlur: 60,
      borderWidth: 1
    },
    tooltip: {
      show: false
    }
  },
  series: [
    {
      name: "",
      type: "lines",
      coordinateSystem: "geo",
      zlevel: 1,
      effect: {
        show: true,
        period: 6,
        trailLength: 0.7,
        color: "red",
        symbolSize: 3
      },
      lineStyle: {
        color: "#fff",
        width: 0,
        curveness: 0.2
      },
      data
    },
    {
      name: "",
      type: "lines",
      coordinateSystem: "geo",
      zlevel: 2,
      symbol: ["none", "arrow"],
      symbolSize: 10,
      effect: {
        show: true,
        period: 6,
        trailLength: 0,
        // symbol: planePath,
        symbol: busPath,
        symbolSize: 15
      },
      lineStyle: {
        color: "#fff",
        width: 1,
        opacity: 0.6,
        curveness: 0.2
      },
      data
    }
  ]
};
</script>

<style lang="scss" scoped>
.echarts {
  width: 100%;
  height: 100%;
}
div {
  width: 100%;
  height: 100%;
}
.map-ball {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  transform: translate(-50%, -50%);
  img {
    width: 500px;
    height: 500px;
  }
}
</style>
